package com.java.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @function:
 * @CreateTime: 2021/3/16 20:15
 */
public interface HouseMapper {
    /**
     * 查询房间类型信息
     * @return
     */
    @Select("select * from room_type")
    List<Map<String, Object>> findRoomType();

    /**
     * 添加房间信息
     * @param roomnum
     * @param roomstatus
     * @param roomtypeid
     * @return
     */
    @Insert({"insert into rooms(room_num,room_status,room_type_id) values(#{0},#{1},#{2})"})
    int saveRooms(String roomnum, String roomstatus, Long roomtypeid);

    /**
     * 查询房间号是否存在
     * @param roomnum
     * @return
     */
    @Select("select COUNT(*) from rooms where room_num = #{0}")
    int getRoomByRoomnum(String roomnum);

    /**
     * 查询房间信息
     */
    @Select("select rs.room_num,rt.room_type_name,rt.room_price,rs.room_status " +
            "from rooms rs " +
            "LEFT JOIN room_type rt on rs.room_type_id = rt.id")
    List<Map<String,Object>> findRooms();

    /**
     * 查询房间状态为空闲的房间信息
     * @param status
     * @return
     */
    @Select("select * from rooms rs where rs.room_status = #{0}")
    List<Map<String, Object>> findRoomBystatus(String status);

    /**
     * 修改房间的状态
     */
    @Update("update rooms set room_status = #{0} where id = #{1}")
    int updateRoomBystatus(String status,Long id);
}
